import Vue from 'vue'
import Vuex from 'vuex'
import menus from '@/store/modules/menus'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    userInfo: {},
  },
  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
      localStorage.setItem('token', token)
    },
    SET_USER: (state, userInfo) => {
      state.userInfo = userInfo
      localStorage.setItem('userInfo', JSON.stringify(userInfo))
    },
  },
  getters: {
    getUserInfo(state) {
      state.userInfo = JSON.parse(window.localStorage.getItem('userInfo'))
      return state.userInfo
    },
  },

  actions: {},
  modules: {
    menus,
  },
})
